package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.mapper.TravelCommendMapper;
import cn.wolfcode.trip.base.query.TravelCommendQuery;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TravelCommendServiceImpl implements ITravelCommendService{

    @Autowired
    private TravelCommendMapper commendMapper;


    @Override
    public PageInfo<TravelCommend> query(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<TravelCommend> list=commendMapper.selectForList(qo);

        return new PageInfo<TravelCommend>(list);
    }


    @Override
    public void saveOrUpdate(TravelCommend travelCommend) {
        if (travelCommend.getId() != null) {
            commendMapper.updateByPrimaryKey(travelCommend);

        }else{
            commendMapper.insert(travelCommend);
        }

    }

    @Override
    public List<Map> queryApp(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Map> maps = commendMapper.selectForAppList(qo);
        return maps;
    }
}
